﻿using _10_Panel_嵌入式窗体.窗体;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _10_Panel_嵌入式窗体
{
    public partial class MainForm : BaesForm
    {
        public MainForm()
        {
            InitializeComponent();

            foreach (Control item in this.panel1.Controls)
            {
                //除了隐藏菜单，每一个按钮绑定对一个的事件
                if (item.Text != "隐藏菜单")
                {
                    item.Click += new System.EventHandler(Btn_Click);
                }
            }
        }

        bool flage = true;//定义一个标记，用来判断菜单是否隐藏

        /// <summary>
        /// 隐藏菜单,响应事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void button6_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 定时器响应事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (flage)//判断是展开还是收缩
            {
                this.panel1.Width += 10;
                if (this.panel1.Width >= 215)
                {
                    this.timer1.Stop();
                    this.panel1.Width = 215;
                }
                this.button6.Image = Properties.Resources.箭头_左_白;
            }
            else
            {
                this.panel1.Width -= 10;
                if (this.panel1.Width <= 45)
                {
                    this.timer1.Stop();
                    this.panel1.Width = 45;
                }
                this.button6.Image = Properties.Resources.箭头_右_白;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.button1.BackColor = Color.Orange;
            this.button2.BackColor = Color.SeaGreen;
            this.button3.BackColor = Color.Orange;
            this.button4.BackColor = Color.Orange;
            this.button5.BackColor = Color.Orange;
            this.button6.BackColor = Color.Orange;
        }

        private void Btn_Click(object sender, EventArgs e)
        {
            Button btn = sender as Button;
            if (btn != null)
            {
                foreach (Button button in this.panel1.Controls)
                {
                    button.BackColor = button.Text == btn.Text ? Color.Tomato : Color.Orange;
                }
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            ShowForm(new Frm_Main(), this.panel2);
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            ShowForm(new Frm_SystemSet(), this.panel2);
        }

        public void ShowForm(Form controlForm, Panel panel)
        {
            foreach (Control item in panel.Controls)
            {
                if (item is Form fr)
                {
                    fr.Close();
                }
            }
            //设置为非顶级窗体
            controlForm.TopLevel = false;
            //设置边框为无边框
            controlForm.FormBorderStyle = FormBorderStyle.None;
            //设置为停靠控件，填充满的模式
            controlForm.Dock = DockStyle.Fill;
            //添加到容器当中
            panel.Controls.Add(controlForm);
            //显示窗体
            controlForm.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            ShowForm(new Frm_License(), this.panel2);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ShowForm(new Frm_Helper(), this.panel2);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            ShowForm(new Frm_LogSystem(), this.panel2);
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void button6_Click_1(object sender, EventArgs e)
        {
            this.timer1.Start();
            if (this.panel1.Width < 215)
            {
                flage = true;
            }
            else
            {
                flage = false;
            }
        }
    }
}
